//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.pss;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.PssLossOrderDao;
import com.aidong.model.wills.PssLossOrderTotal;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.pss.PopProductController;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"productGainsLossesList"})
public class ProductGainsLossesListController extends PopProductController {
    @Resource
    PssLossOrderDao pssLossOrderDao;

    public ProductGainsLossesListController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("pss/productgainslosseslist/list")).addObject("shopName", this.getTypeList("shopName"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "baosunyiDateFrom",required = false) String baosunyiDateFrom, @RequestParam(value = "baosunyiDateTo",required = false) String baosunyiDateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "LossShop", shopCode);
        if(!this.chkNull(baosunyiDateFrom)) {
            cd.ge("LossDate", this.parseDate(baosunyiDateFrom, "yyyy-MM-dd"));
        }

        if(!this.chkNull(baosunyiDateTo)) {
            cd.le("LossDate", this.parseDate(baosunyiDateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
        }

        this.pssLossOrderDao.getLstLossOrderDetailList(pg, cd);
        ModelAndView mv = new ModelAndView("pss/productgainslosseslist/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("shopName", this.getTypeList("shopName"));
        mv.addObject("productUnit", this.getTypeList("productUnit"));
        mv.addObject("ProductcodeList", this.getTypeList("ProductcodeList"));
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "baosunyiDateFrom",required = false) String baosunyiDateFrom, @RequestParam(value = "baosunyiDateTo",required = false) String baosunyiDateTo, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, 20000);
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "LossShop", shopCode);
            if(!this.chkNull(baosunyiDateFrom)) {
                cd.ge("LossDate", this.parseDate(baosunyiDateFrom, "yyyy-MM-dd"));
            }

            if(!this.chkNull(baosunyiDateTo)) {
                cd.le("LossDate", this.parseDate(baosunyiDateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
            }

            this.pssLossOrderDao.getLstLossOrderDetailList(e, cd);
            ExportXls xls = new ExportXls(response, "商品保损溢流水", "商品保损溢流水");
            xls.addHead(new String[]{"报损部门编号编号", "报损部门编号名称", "商品编码", "商品名称", "单位", "数量", "报损溢日期", "操作员", "备注"});
            xls.setWidth(new int[]{10, 25, 10, 25, 10, 10, 10, 20});
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                PssLossOrderTotal puot = (PssLossOrderTotal)i$.next();
                xls.addRow(new Object[]{puot.getLossShop(), this.cache.getValue("shopName", puot.getLossShop()), puot.getProductCode(), this.cache.getValue("ProductcodeList", puot.getProductCode()), this.cache.getValue("productUnit", puot.getUnit()), puot.getQty(), puot.getLossDate(), this.cache.getValue("userName", puot.getCreateUser()), puot.getNote()});
            }

            xls.close();
            this.addUserLog("导出商品报损溢流水", e.getResultList().size() + "条记录");
        } catch (Exception var10) {
            this.log.error("import", var10);
        }

        return null;
    }
}
